#pragma once

#include "noncopyable.h"

#include <thread>
#include <functional>
#include <memory>
#include <string>
#include <atomic>

class Thread : noncopyable
{
public:
  using Functor = std::function<void()>;
  explicit Thread(Functor, const std::string& name = std::string());
  ~Thread();
  void start();
  void join();
  bool started() { return m_started; }
  pid_t pid() { return m_pid; }
  const std::string& name() const { return m_threadName; }
  static int32_t numCreated() { return m_numCreated.load(); }
  // void setDefaultName();
private:
  bool m_started;
  bool m_joined;
  std::shared_ptr<std::thread> m_thread;
  pid_t m_pid;
  Functor m_func;
  std::string m_threadName;
  static std::atomic<int32_t> m_numCreated;
};